<?php
class Template{
	function display($contents,$seller_id=""){
		$this->load->model('public_model');
		// get main template with URL
		$webstoreObj=$this->public_model->getTemplateForUrl();
		$template="";
		$webstore="";
		if(count($webstoreObj)==0){
   			//get template of givemart in system parameters
   			$template="default";
   			$webstore="";
   		}else{
   			$template=$webstoreObj['templatecode'];
   			$webstore=$webstoreObj['webstore'];
   		}
   		// define positions of template
   		$positions=array('menu','search','left','right','footer','header','mainmenu','productviewed','morebuying','logo');
   		if(modules::run('login/is_admin_logged_in') == true) {
			$modules=array('menu'=>'menu','mainmenu'=>'mainmenu','productviewed'=>'productviewed','morebuying'=>'morebuying','logo'=>'logo');
		}
		else{
			$modules=array('menu'=>'menu','mainmenu'=>'mainmenu','productviewed'=>'productviewed','morebuying'=>'morebuying','logo'=>'logo');	
		}

   		foreach($positions as $position){
   			// load active modules of menu position on this template
   			foreach($modules as $module=>$pos){
   				if($pos==$position){
   					$data_template[$pos]='';
   					if($seller_id=="" && $module == "categorysite"){
   						$data_template[$pos] = $this->public_model->getModuleWithCache($module);
   					}else $data_template[$pos] .= modules::run($module,$seller_id);	
   				}
   			}
   		}
   		//$data_template['menu'] = modules::run('menu');
   		$data_template['contents']=$contents;
   		$data_template['seller_id']=$seller_id;
   		if($this->config->item('WebstoreId')==0){
   			if($this->config->item('ismobile')==1 && $this->config->item('fullsize')==0){
   				$template='mobile';
   			}
   			$this->load->view('templates/'.$template.'/'.$template, $data_template);
   		}else{
   			if($webstoreObj['status']=='Active'){
   				if($this->config->item('ismobile')==1 && $this->config->item('fullsize')==0){
   				$templateformobil='mobile';
   				$this->load->view('templates/'.$template.'/'.$templateformobil.'/'.$templateformobil, $data_template);
	   			}else{
	   				$this->load->view('templates/'.$template.'/'.$template, $data_template);
	   			}
   			}else{
   				die('This Store has been not yet active');
   			}
   		}
   		
		
	}
	function formatOrderNum($orderid=0, $prefix = PREFIX_CODE){
		// Format order number
		$orderNumber = $prefix;
		for($i = 0; $i < (10 - strlen($orderid)); $i++) $orderNumber .= "0";
		$orderNumber .= $orderid;
		return $orderNumber;
	}
}
?>
